1. Field of the Invention
The present invention generally relates to the field of computer programs, compilers, and object-oriented programming.
2. Description of the Related Art
Computer programs are constructed using one or more programming languages. A computer programmer first drafts a source code (i.e., a computer program) in human-readable form. The computer programmer then uses a compiler to convert the source code into a machine-readable form called object code. The compiler may reside within the memory of the computer that will be used to execute the object code, or it may reside on a separate computer system.
Many types of programming languages are used by computer programmers to create source code. Some exemplary programming types include an aspect-oriented programming, a functional programming, and an objected-oriented programming. Object-oriented programming languages (OOP) are organized around an object rather than an action, as in procedural languages. The object is a self-contained collection of data and its associated processing language. Examples of OOP languages include the Java® and C++ programming languages.
The first step in the OOP is to identify all the objects one desires to manipulate and determine how those objects relate to each other, often known as data modeling. Once one has identified the object, one generalizes it as a class and defines the type of data the class may contain and any logical sequences that may manipulate it. The class is a set of objects that share a common structure and behavior. The structure of the class is determined by a class variable which represents the state of an object of that class, with the behavior given by a set of methods associated with the class. A real instance of a class is called an “object” or, in some environments, a “class instance.” The object or class instance is what is run while executing a program in the computer. The object's methods provide computer instructions, while the class object characteristics provide relevant data. Communication with objects is done with well-defined interfaces called messages.
During programming, the computer programmer creates objects by instantiating (declaring) them. Upon creation, the object may either be a default size or a size determined by the computer programmer. However, many objects in the OOP are expandable. In other words, if, during execution of a program, the object reaches its size limitation, it may automatically expand itself to a larger size to accommodate its need. The Java® programming language, in particular, has several classes of objects that allow instances of the objects themselves to be automatically expanded. Examples of these classes include StringBuffer and Vector. Automatic expansion of the object is inherently problematic as the underlying code has no manner of determining how much to increase the object's size. Thus, the typical default expansion is double. The object is expanded by the program creating a new object, twice as large as the object being expanded. The program then copies all the data from the old object into the new object.
The expansion process sometimes leads to an over-allocation of space to the object. For example, suppose the initial object size is 40-bytes, and all the allocated space contains data. If the program needs to place more information in the object, expansion must occur, doubling the object to 80-bytes. If this process continues, the object will continue to expand from 80-bytes to 160-bytes to 320-bytes to 640-bytes, etc. If the object is full at 640-bytes, but the program needs to place one more byte of data in the object, the object must be doubled (to 1240-bytes), just to accommodate one single byte, essentially a waste of 630-bytes. Additionally, there is a waste of the time it takes to copy the data to the new object, and that missing bytes in the data causes cache misses to occur more often, wasting computer processor cycles.
Therefore, there is a need for a method or system that permits source code to be analyzed to determine if the default object capacity should be changed.